package com.yanchangapp.ui.activity.manage;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.zxl.baselib.ui.base.BaseActivity;
import com.zxl.baselib.util.ui.UIUtils;
import com.yanchangapp.R;
import com.yanchangapp.adapter.WorkComposeAdapter;
import com.yanchangapp.model.bean.ComposeMenuIcons;
import com.yanchangapp.ui.presenter.MgAtPresenter;
import com.yanchangapp.ui.view.MgAtView;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;

/**
 * 我的管理首页面...
 */
public class ManageHomeActivity extends BaseActivity<MgAtView, MgAtPresenter> implements MgAtView {
    @BindView(R.id.ivToolbarNavigation)
    ImageView ivToolbarNavigation;
    @BindView(R.id.vToolbarDivision)
    View vToolbarDivision;
    @BindView(R.id.tvToolbarTitle)
    TextView tvToolbarTitle;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private WorkComposeAdapter mWorkComposeAdapter;
    private List<ComposeMenuIcons> mComposeMenuIconsList = new ArrayList<>();

    @Override
    protected void init() {

    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_mange_home;
    }

    @Override
    protected MgAtPresenter createPresenter() {
        return new MgAtPresenter(this);
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvToolbarTitle.setText("我的管理");
        initWorkAdapter();
    }

    private void initWorkAdapter() {
        recyclerView.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
        mWorkComposeAdapter = new WorkComposeAdapter(R.layout.item_compose_rv,mComposeMenuIconsList,this);
        recyclerView.setAdapter(mWorkComposeAdapter);
    }

    @Override
    protected void initData() {
        mPresenter.fetchList();
    }

    @Override
    protected void initListener() {
        ivToolbarNavigation.setOnClickListener(v -> finish());
    }

    @Override
    public void queryMenuListSuccess(List<ComposeMenuIcons> menuIcons) {
        mComposeMenuIconsList.clear();
        mComposeMenuIconsList.addAll(menuIcons);
        mWorkComposeAdapter.notifyDataSetChanged();
    }

    @Override
    public void queryMenuListFailure(String msg) {
        UIUtils.showToast(msg);
    }
}
